import Vue from 'vue'
import Router from 'vue-router'
import login from "@/views/login/login";

Vue.use(Router);

export const constantRoutes = [
    {
        path: '',
        redirect: '/login',
    },
    {
        path: '/login',
        name: 'Login',
        component: login,
    },

    {
        path: '/home',
        name: 'Home',
        component: () => import("@/views/home/index")
    },
    {
        path: '/home/work',
        name: 'work',
        component: () => import("@/views/home/work/index"),
        children: [
            {
                path: 'suggest/index',
                name: 'suggest',
                component: () => import("@/views/home/work/suggest/index")
            },
            {
                path: 'my-task/index',
                name: 'myTask',
                component: () => import("@/views/home/work/myTask/index")
            },

        ]
    },
    {
        path: '/home/work/add/index',
        name: 'Add',
        component: () => import("@/views/home/work/add/index")
    },
    {
        path: '/home/work/ins/index',
        name: 'ins',
        component: () => import("@/views/home/work/ins/index")
    },

]

const createRouter = () => new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({y: 0}),
    routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher; // reset router
}

export default router
